package de.dlrg.wms.controller.controllers;

import java.util.List;

import javax.management.RuntimeErrorException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import de.dlrg.wms.controller.interfaces.ICRUD;
import de.dlrg.wms.dao.SwimmerDao;
import de.dlrg.wms.model.Swimmer;

@Component
public class SwimmerController implements ICRUD<Swimmer> {
	@Autowired
	private SwimmerDao swimmerDao;
	@Autowired
	private AgeClassController ageClassController;
	
	public AgeClassController getAgeClassController() {
		return this.ageClassController;
	}
	
	public List<Swimmer> readAll() {
		return this.swimmerDao.readAll();
	}

	public void createOrUpdate(Swimmer toCreateOrUpdate) {
		this.swimmerDao.save(toCreateOrUpdate);		
	}

	public void delete(Swimmer toDelete) {
		this.swimmerDao.delete(toDelete);
	}

	public void validate(Swimmer toValidate) {
		if(toValidate.getAgeClass()==null) {
			throw new RuntimeErrorException(null);
		}
	}

	public Long getTotalCountSwimmer() {
		return this.swimmerDao.count();
	}
}
